package com.example.administrator.yuejian35.Find.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian35.Find.FindModel;
import com.example.administrator.yuejian35.Find.adapter.FindAdapter;
import com.example.administrator.yuejian35.Find.adapter.FindAdapter1;
import com.example.administrator.yuejian35.Find.bean.Post;
import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.base.BaseActivity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MypostActivity extends AppCompatActivity {
    private FindAdapter1 adapter;
    private RecyclerView rv;
    private ImageView ic_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mypost);
        rv = (RecyclerView) findViewById(R.id.post_rv);
        ic_back = (ImageView) findViewById(R.id.ic_back);

        ic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        String Uid = BaseActivity.getUserId();
        FindModel findModel = new FindModel();
        Call call = findModel.getPostByUser(Uid);
        call.enqueue(new Callback<List<Post>>() {
            @Override
            public void onResponse(Call<List<Post>> call, Response<List<Post>> response) {
                List<Post> post = response.body();
                adapter = new FindAdapter1(MypostActivity.this, post);
                LinearLayoutManager layoutManager = new LinearLayoutManager(MypostActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);//Horizontal
                rv.setLayoutManager(layoutManager);
                rv.setAdapter(adapter);
                rv.setItemAnimator(new DefaultItemAnimator());

            }

            @Override
            public void onFailure(Call<List<Post>> call, Throwable t) {

            }
        });






    }
}
